package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    float dollar_rate,euro_rate,won_rate;
    TextView result;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent=getIntent();
        dollar_rate=intent.getFloatExtra("new_dollar_rate_key",1.2f);
        euro_rate=intent.getFloatExtra("new_euro_rate_key",0.3f) ;
        won_rate=intent.getFloatExtra("new_won_rate_key",0.2f) ;
        SharedPreferences sp=getSharedPreferences("myrate",Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        editor.putFloat("new_dollar_rate_key",dollar_rate);
        editor.putFloat("new_euro_rate_key",euro_rate);
        editor.putFloat("new_won_rate_key",won_rate);
        editor.apply();
    }

        public void mycilck(View btm){
        result=findViewById(R.id.hi);
        EditText rmb=findViewById(R.id.input);
        if(rmb.length()==0){
            Toast.makeText(this,"请输入数值",Toast.LENGTH_SHORT).show();
            return;
        }
        String str=rmb.getText().toString();
        String in=rmb.getText().toString();
        float input=Float.valueOf(in);
        float r=0.0f;
        if(btm.getId()==R.id.dollar_btm){
            r=input*dollar_rate;
        }
        else if(btm.getId()==R.id.euro_btm){
            r=input*euro_rate;
        }
        else{
            r=input*won_rate;
        }
        result.setText("结果"+r);
    }
    public void open(View btn){
        Intent config=new Intent(this,configActivity2.class);
        config.putExtra("dollar_rate_key",dollar_rate);
        config.putExtra("euro_rate_key",euro_rate);
        config.putExtra("won_rate_key",won_rate);
        startActivity(config);
    }
}